var hrid;
$(function  () {
    
    
    $("#huname").html($.cookie("lname"));
    showtime();

    hrid = $.cookie("ltype");

    if(hrid==1){
        $("#rightcontent").attr('src','./stuStatistics.html');
    }else{
        $("#rightcontent").attr('src','./teaStatistics.html');
    }

    var uuname = $.cookie("lname");
    if(hrid==0){
        //获取菜单
        if(uuname!=0){
            $.post(
                ipurl+'/menu/get',
                function(result) {
                    if(result.code == 200){
                        var menulist = result.data.results;
                        var menuhtml = '';
                        for(var i=0;i<menulist.length;i++){
                            menuhtml+='<li class="list">';
                            menuhtml+='<a href="javascript:;" onclick="menugo('+"'"+menulist[i].maddress+"'"+')">';
                            menuhtml+='<i class="iconfont">&#xe70b;</i>';
                            menuhtml+=menulist[i].name;
                            menuhtml+='<i class="iconfont nav_right">&#xe697;</i>';
                            menuhtml+='</a></li>';
                        }
                        $("#nav").html(menuhtml);
                    }
                }
            );
        }else{
            $("#rightcontent").attr('src','./404.html');
        }
    }else{
        //根据权限获取菜单
        $.ajax({
            url: ipurl+'/per/get',
            data: {
                rid:hrid
            },
            type: "POST",
            //dataType: "json",

             success: function(resultper) {
                var perlist = resultper.data.results;
                var menuhtml = '';
                for(var i=0;i<perlist.length;i++){
                    menuhtml+='<li class="list">';
                    menuhtml+='<a href="javascript:;" onclick="menugo('+"'"+perlist[i].maddress+"'"+')">';
                    menuhtml+='<i class="iconfont">&#xe70b;</i>';
                    menuhtml+=perlist[i].name;
                    menuhtml+='<i class="iconfont nav_right">&#xe697;</i>';
                    menuhtml+='</a></li>';
                }
                $("#nav").html(menuhtml);
            }
        });
    }
})

function menugo(address){
    $("#rightcontent").attr('src',address);
}

//退出登录
function logout(){
    var date=new Date();
    date.setTime(date.getTime()-10000);
    var keys=document.cookie.match(/[^ =;]+(?=\=)/g);
    console.log("需要删除的cookie名字："+keys);
    if (keys) {
       for (var i =  keys.length; i--;)
        document.cookie=keys[i]+"=0; expire="+date.toGMTString()+"; path=/";
    }
    window.location.href='index.html';
}


function changepass(title,url,w,h){
    x_admin_show('修改密码','./changepass.html',500,510);
}

function usercenter(){
    if(hrid==1){
        $("#rightcontent").attr('src','./usercenter.html');
    }else{
        $("#rightcontent").attr('src','./teacenter.html');
    }
}


function showtime(){
 
    var today,hour,second,minute,year,month,date;
 
    var strDate ;
 
    today=new Date();
 
    var n_day = today.getDay();
 
    switch (n_day){
 
        case 0:{
 
          strDate = "星期日"
 
        }break;
 
        case 1:{
 
          strDate = "星期一"
 
        }break;
 
        case 2:{
 
          strDate ="星期二"
 
        }break;
 
        case 3:{
 
          strDate = "星期三"
 
        }break;
 
        case 4:{
 
          strDate = "星期四"
 
        }break;
 
        case 5:{
 
          strDate = "星期五"
 
        }break;
 
        case 6:{
 
          strDate = "星期六"
 
        }break;
 
        case 7:{
 
          strDate = "星期日"
 
        }break;
 
    }
 
    year = today.getFullYear();
 
    month = today.getMonth()+1;
 
    date = today.getDate();
 
    hour = today.getHours();
 
    minute =today.getMinutes();
 
    second = today.getSeconds();
 
 
 
    if (month >= 1 && month <= 9) {
 
        month = "0" + month;
 
    }
 
    if (date >= 0 && date <= 9) {
 
        date = "0" + date;
 
    }
 
    if (hour >= 0 && hour <= 9) {
 
        hour = "0" + hour;
 
    }
 
    if (minute >= 0 && minute <= 9) {
 
        minute = "0" + minute;
 
    }
 
    if (second >= 0 && second <= 9) {
 
        second = "0" + second;
 
    }
 
    document.getElementById('timenow').innerHTML = hour + ":" + minute + ":" + second; //显示时间
 
    setTimeout("showtime();", 1000); //设定函数自动执行时间为 1000 ms(1 s)
 
}
